import * as mongoose from 'mongoose';

export const TypeSchema = new mongoose.Schema({
  /* 类型名称（英文） */
  name: String,
  desc: String,
  intro: String,
  hash: String,
  path: String,
  size: Number,
  tags: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  type: String,
  mainComponent: String,
  fkId: mongoose.SchemaTypes.ObjectId,
  projectId: mongoose.SchemaTypes.ObjectId,
  fileName: String,
  language: String,
  folder: String,
  folderPath: String,
  linkPath: String,
  routePath: String,
  routeMenuName: String,
  noLayout: Boolean,
  fields: Array,

  data: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  /**
   * API使用
   */
  uri: String,
  method: String,
  timeout: Number,
  headers: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  /**
   * 参数
   * 1.用于API，表达此接口可接收的参数
   * 2.用于Action，表达此函数可接收的参数
   */
  params: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  query: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  pathParams: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },
  isCors: Boolean,
  contentType: String,
  cases: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  db: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  access: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  validations: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  transformers: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  lifeCycle: String,
  code: Object,
  source: String,

  /* Api 文档 */
  apiDocUrl: String,
  apiDocStr: String,
  hostConstantName: String,
  host: String,
  basePath: String,

  /**
   * 去重字符
   */
  unikey: String,
  from: {
    type: mongoose.Schema.Types.Mixed,
    required: false,
  },

  extends: Object,

  userId: Number,
  teamId: Number,
  create_time: Number,
  update_time: Number,
});

export type IContentTypeEnctype =
  | 'application/x-www-form-urlencoded'
  | 'text/plain'
  | 'multipart/form-data';
